<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/2/21 0021
 * Time: 13:56
 */

namespace app\index\model;

use think\exception\ErrorException;
use think\Model;
use think\Log;

class Category extends Model
{
    /**
     * @Notes:   产品分类列表（需要）
     * @User:    this邹
     * @CreateDate:  2019/2/21 0021 14:05
     * @return false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function findCategoryList()
    {
        try {
            $categoryList = $this->where('show', 1)->order('sort desc')->limit(20)->select();
            return $categoryList;
        } catch (ErrorException $e) {
            Log::write('查询错误，错误信息：' . $e->getMessage(), 'error');
        }
    }

    /**
     * @Notes:   按产品分类ID查找分类详细信息（需要）
     * @User:    this邹
     * @CreateDate:  2019/2/21 0021 14:12
     * @param $id
     * @return array|false|\PDOStatement|string|Model
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function findCategoryById($id)
    {
        try {
            $categoryItem = $this->where('id', $id)->field('id,name,icon,keywords,description')->find();
            return $categoryItem;
        } catch (ErrorException $e) {
            Log::write('查询错误，错误信息：' . $e->getMessage(), 'error');
        }
    }
}